package com.example.demo.service.impl;



import com.example.demo.dao.dishDAO;
import com.example.demo.model.dish;
import com.example.demo.service.dishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.List;

@Component
public class dishServiceImpl implements dishService {
    @Autowired
    private dishDAO dishDAO;
    @Override
    public List<dish> getAllDishes() {
        List<dish> dishes = dishDAO.listAllDishes();
        if (dishes == null){
            return null;
        }
        return dishes;
    }

    @Override
    public int add(dish dish) {
        if (dish==null){
            return 0;
        }
        return dishDAO.add(dish);
    }

    @Override
    public int update(dish dish) {
        if (dish==null){
            return 0;
        }
        return dishDAO.update(dish);
    }

    @Override
    public int delete(int id) {
         if (id>0){
            return dishDAO.delete(id);
        }
        return 0;
    }

    @Override
    public dish findByDishName(String dishName) {
        if (StringUtils.hasText(dishName)){
            return dishDAO.findByDishName(dishName);
        }
        return null;
    }
}
